package com.cqch.service.impl;

import com.cqch.dao.PassengerRepository;
import com.cqch.dao.UserRepository;
import com.cqch.pojo.entity.Passenger;
import com.cqch.pojo.entity.User;
import com.cqch.pojo.repVo.BaseResp;
import com.cqch.service.IPassengerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @Author CQCH
 * @Description
 * @Date 2022/3/30
 */
@Service
public class PassengerService implements IPassengerService {

    @Autowired
    UserRepository userRepository;

    @Autowired
    PassengerRepository passengerRepository;

    public  List<Passenger> passengers;
    @Override
    public BaseResp findAll(Integer uid) {

        List<Passenger> byUid = passengerRepository.findByUid(1);

        System.out.println(byUid);

        List<Passenger> list = new ArrayList<>();

        for (Passenger passenger:byUid){
            Integer aid = passenger.getAid();

            Optional<User> byId = userRepository.findById(aid);

            Passenger passenger1 = new Passenger();

            passenger1.setCount(passenger.getCount());
            passenger1.setAid(aid);
            passenger1.setUser(byId.get());
            passenger1.setId(passenger.getId());

            list.add(passenger1);
        }
        return new BaseResp(1,"查询成功",list,null);
    }
}
